Ektron CMS400.Net Reference

>>Working with Ektron CSM400.NET Server Controls > Using Ajax Enabled Server Controls and Custom Code

Using Ajax Enabled Server Controls and Custom Code

Best Practice

When using Ajax server controls and custom code, wrap the custom code in a check for “is not a callback,” so it is not executed when a callback from an Ajax server control occurs.

If you use an Ajax-enabled server control and write custom code, it may generate an exception, indicating the server control does not work. This issue happens during callback for the Ajax server control when custom code accesses a property that is filled during page load, but not filled during callback.

For example, a Poll server control is on a Web form, and you want the title of a content block to appear in a literal on that form. The EkItem.Title property for the content block is filled upon page load. When a site user answers the poll question, an exception occurs during the callback because the EkItem.Title property is not refilled. However, the site user does not see the exception. It just looks like the Poll server control is not working.

Below is an example of custom code that makes the content block’s title appear in the literal:

Literal1.Text = ContentBlock1.EkItem.Title

To solve this issue, wrap the custom code in a check for “is not a callback”. This prevents the code execution when callback occurs. For example,

[C#]

If( !IsCallback ) {

Literal1.Text = ContentBlock1.EkItem.Title

}

[VB]

If ( Not IsCallback )

Literal1.Text = ContentBlock1.EkItem.Title

End If

(continued in Displaying Custom XML in Ektron’s Server Controls)


Visit the Ektron Dev Center at http://dev.ektron.com 1-866 - 4 - EKTRON

Ektron CMS400.NET Reference Version 8.02 SP1 Rev 1

Ektron Documentation,© 2011 Ektron, Inc.